<%@ page import="com.zretc.entity.Account" %><%--
  Created by IntelliJ IDEA.
  User: YuanDali
  Date: 2020/7/20
  Time: 20:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>网站后台管理模版</title>
    <link rel="stylesheet" type="text/css" href="../../front/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../../front/css/admin.css"/>
</head>
<body>
<div class="layui-tab page-content-wrap">
    <ul class="layui-tab-title">
        <li class="layui-this">个人信息</li>
        <li>修改密码</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form"  style="width: 90%;padding-top: 20px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">ID：</label>
                    <div class="layui-input-block">
                        <li type="" name="id"  class="layui-input layui-disabled" >${sessionScope.account.accountId}</li>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名：</label>
                    <div class="layui-input-block" >
                        <li type="" name="username"class="layui-input layui-disabled" >${sessionScope.account.accountName}</li>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">用户头像</label>
                    <div class="layui-input-block">
                        <img src="../fileDownload/${sessionScope.account.facePicture}" style="width: 100px;height: 100px;border-radius: 50%">
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-tab-item">
            <form class="layui-form"  style="width: 90%;padding-top: 20px;" id="updateForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名：</label>
                    <div class="layui-input-block" id="accountName">
                        <input type="text" name="username" id="userName" class="layui-input" value="${sessionScope.account.accountName}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">旧密码：</label>
                    <div class="layui-input-block" id="oldPassword">
                        <input type="password" name="password1" id="password1" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" value="${sessionScope.account.password}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码：</label>
                    <div class="layui-input-block" id="newPassword">
                        <input type="password" name="password2" id="password2" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" >
                    </div>
                </div>
               <%-- <div class="layui-form-item">
                    <label class="layui-form-label">重复密码：</label>
                    <div class="layui-input-block">
                        <input type="password" name="password3" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>--%>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="adminPassword" id="submitPass">立即提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="../../front/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.min.js" ></script>
<%--<script type="text/javascript" src="js/common.js" ></script>--%>
<script>
    //Demo
    layui.use(['form','element'], function(){
        var form = layui.form();
        var element = layui.element();
        form.render();
        //监听信息提交
        form.on('submit(adminInfo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
        //监听密码提交
        form.on('submit(adminPassword)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    $("#submitPass").click(function () {
        // 判断新旧密码是否相同
        var password1 = $("#password1").val();
        var password2 = $("#password2").val();
        var accountName = $("#userName").val();

        // var formData = $("#updateForm").serialize();
        if (password1 == password2){
            alert("新旧密码相同")
        } else {
            $.ajax({
                async:true,
                url:"${pageContext.request.contextPath}/account/updatePassword",
                type:"GET",
                contentType:"application/json",
                data:{
                    accountName:"${sessionScope.account.accountName}",
                    newPassword:password2
                },
                dataType:"json",
                success:function (result) {
                    console.log(result);
                    if (result == 1) {
                        window.location.href = "login.jsp";
                    } else {
                        alert("更新失败!");
                    }
                },
                error:function () {
                    alert("异步请求失败!");
                }
            })
        }
    })

</script>
</body>
</html>
